package com.yc.ui;

import org.eclipse.swt.widgets.Composite;
import java.io.ByteArrayInputStream;
import java.util.List;
import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import com.yc.Idao.GoodsIDao;
import com.yc.dao.GoodsDao;
import com.yc.utils.SWTUtil;
import com.yc.utils.StringUtil;
import org.eclipse.swt.layout.FillLayout;



public class Appraise extends Composite {
	private Table table;
	GoodsIDao dao = new GoodsDao();
	private byte[] bt;//图片的字节数组
	private String xingji = "";
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public Appraise(Composite parent, int style) {
		super(parent, SWT.NONE);
		setLayout(null);
		
		table = new Table(this, SWT.BORDER | SWT.FULL_SELECTION);
		table.setBounds(0, 0, 1033, 597);
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		
		TableColumn tblclmnNewColumn = new TableColumn(table, SWT.CENTER);
		tblclmnNewColumn.setWidth(151);
		tblclmnNewColumn.setText("房间号");
		
		TableColumn tblclmnNewColumn_1 = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn_1.setWidth(119);
		tblclmnNewColumn_1.setText("姓名");
		
		TableColumn tblclmnNewColumn_5 = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn_5.setWidth(127);
		tblclmnNewColumn_5.setText("星级评价");
		
		TableColumn tblclmnNewColumn_2 = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn_2.setWidth(295);
		tblclmnNewColumn_2.setText("评价");
		
		TableColumn tblclmnNewColumn_4 = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn_4.setWidth(320);
		tblclmnNewColumn_4.setText("酒店回复");
		showinfo();
	}
	
	private void showinfo() {
		
		//查询信息‘
		List<Map<String, Object>> list = dao.findAddappraise();
		TableItem tableItem = null;
		//判空
		if(null == list || list.isEmpty()) {
			SWTUtil.showMessage(getShell(), "温馨提示");
			return;
		}
		//有信息  循环
		for(Map<String, Object> m : list) {
			tableItem = new TableItem(table, SWT.NONE);
			if(m.get("a_id").toString().equals("0")) {
				xingji = "★★★★★";
			}else if(m.get("a_id").toString().equals("1")){
				xingji = "★★★★☆";
			}else if(m.get("a_id").toString().equals("2")){
				xingji = "★★★☆☆";
			}else if(m.get("a_id").toString().equals("3")){
				xingji = "★★☆☆☆";
			}else if(m.get("a_id").toString().equals("4")){
				xingji = "★☆☆☆☆";
			}else {
				xingji = "☆☆☆☆☆";
			}
			tableItem.setText(new String[] {
				StringUtil.toString(m.get("r_id")),
				StringUtil.toString(m.get("c_name")),
				xingji,
				StringUtil.toString(m.get("a_datil")),
				StringUtil.toString(m.get("a_reply"))
			});
			bt = ( byte[] )m.get("a_image");
			// 字节数组判空
			if( null != bt) {
				Image image = SWTUtil.imageSize(120, 50, new ByteArrayInputStream(bt));
				tableItem.setImage(5, image);
			}
		}
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

}
